Skip to content

feat: wire ClaimsService and ClaimsController initialization - #9588

Open
tuna1207 wants to merge 23 commits into
mainfrom
feat/claim-controller-mm-wallet
Open

feat: wire ClaimsService and ClaimsController initialization#9588
tuna1207 wants to merge 23 commits into
mainfrom
feat/claim-controller-mm-wallet

Conversation

@tuna1207

Copy link
Copy Markdown
Member

Explanation

Adds ClaimsService and ClaimsController as default initialized units in the @metamask/wallet package, following the existing InitializationConfiguration pattern used by TransactionController, StorageService, and other wallet instances.

@metamask/wallet is the shared controller-integration layer for extension, mobile, and other clients, so build-specific and runtime values are injected via instanceOptions rather than hardcoded.

ClaimsService — selects the Claims API environment and platform fetch implementation. instanceOptions.claimsService.env and instanceOptions.claimsService.fetchFunction are required. The wallet init delegates AuthenticationController:getBearerToken to the service messenger; hosts must register AuthenticationController on the supplied root messenger before authenticated Claims API calls succeed.

ClaimsController — stateful controller with no additional constructor options beyond optional persisted state. The wallet init delegates only the ClaimsService actions the controller calls (fetchClaimsConfigurations, getRequestHeaders, getClaimsApiUrl, generateMessageForClaimSignature, getClaims) plus KeyringController:signPersonalMessage.

Wallet release work is intentionally deferred; this PR lands the integration and documents consumer options only.

References

Per-environment options

Option Extension Mobile Default (Node / tests / wallet-cli)
claimsService.env Build flavor (Env.DEV / Env.UAT / Env.PRD) Build flavor (Env.DEV / Env.UAT / Env.PRD) Env.PRD in wallet-cli; Env.DEV in wallet unit tests
claimsService.fetchFunction Platform fetch Platform fetch globalThis.fetch
claimsController state Persisted via wallet state blob when supplied Persisted via wallet state blob when supplied Optional; defaults apply when omitted
AuthenticationController:getBearerToken Host must register AuthenticationController on the wallet root messenger (not an instanceOptions slot) Host must register AuthenticationController on the wallet root messenger (not an instanceOptions slot) Not wired in wallet-cli; authenticated Claims calls require host auth wiring

Verification

  • yarn workspace @metamask/wallet run test
  • yarn workspace @metamask/wallet run jest --no-coverage src/initialization/instances/claims-service/claims-service.test.ts src/initialization/instances/claims-controller/claims-controller.test.ts
  • yarn workspace @metamask/wallet run messenger-action-types:check
  • yarn workspace @metamask/wallet run lint:tsconfigs
  • yarn workspace @metamask/wallet-cli run lint:tsconfigs
  • yarn readme-content:check
  • yarn codeowners:check
  • yarn lint:teams

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and documented required consumer options in the table above
  • Wallet release deferred to a follow-up request

Made with Cursor

tuna1207 and others added 10 commits July 22, 2026 15:09
Add default wallet initialization units for ClaimsService and
ClaimsController with tight messenger delegation, required
claimsService instance options, wallet-cli defaults, ownership, and
dependency graph updates.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Colocate ClaimsService with ClaimsController so a single CODEOWNERS
initializationPath covers both units, and revert multi-path ownership.

Co-authored-by: Cursor <cursoragent@cursor.com>
Match the SubscriptionEnv naming pattern so wallet consumers can set
claimsService.env without colliding with other Env enums.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@tuna1207
tuna1207 marked this pull request as ready for review July 23, 2026 00:58
@tuna1207
tuna1207 requested review from a team as code owners July 23, 2026 00:58
@tuna1207
tuna1207 temporarily deployed to default-branch July 23, 2026 00:58 — with GitHub Actions Inactive
@tuna1207 tuna1207 changed the title feat(wallet): wire ClaimsService and ClaimsController initialization feat: wire ClaimsService and ClaimsController initialization Jul 23, 2026
Comment thread packages/wallet/src/initialization/instances/claims-controller/types.ts Outdated
Comment thread packages/wallet/src/initialization/instances/claims-controller/types.ts Outdated
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
claimsService: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? TransactionController doesn't interact with claims though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to #9588 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really required for the test file only, since no change has been made to the corresponding controller initialization file? If not, please remove

Comment thread packages/wallet/src/index.ts Outdated
export type InstanceSpecificOptions = {
approvalController?: ApprovalControllerInstanceOptions;
claimsService: ClaimsServiceInstanceOptions;
claimsController?: ClaimsControllerInstanceOptions;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I know why is claimsController optional but claimsService is required?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controller only needs state and messenger, which initialization already provides. There's nothing for the consumer to configure, so the slot is optional.
Claim Service need required fetchFunction option

Comment thread packages/wallet/CHANGELOG.md Outdated
@lwin-kyaw

Copy link
Copy Markdown
Contributor

One more thing I noticed is that shield/subscriptions/claims controllers have the different constructor interfaces.

Some accept ENV and some accept URL. I think they should be consistent.
And what's your thought on replacing ClaimsEnv SubscriptionsEnv with ENV from the AuthenticationController?

@pedronfigueiredo pedronfigueiredo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there's a bunch of comments and merge conflicts, can you address them and then re-request my review here on github once it's ready for another look?

Comment thread packages/wallet-cli/src/daemon/wallet-factory.ts Outdated
@tuna1207
tuna1207 requested a review from a team as a code owner July 30, 2026 13:06
@tuna1207

tuna1207 commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

One more thing I noticed is that shield/subscriptions/claims controllers have the different constructor interfaces.

Some accept ENV and some accept URL. I think they should be consistent. And what's your thought on replacing ClaimsEnv SubscriptionsEnv with ENV from the AuthenticationController?

Env is a generic infra concept, not an auth concept. Making claims/subscription/shield depend on profile-sync for a 3-value enum couples unrelated packages - every profile-sync major bump (it's at v28, moves fast) forces churn in dependents. claims/subscription currently only use it type-only; adding a runtime import makes it a real dependency.

I think we can move Env into a neutral shared package - @metamask/controller-utils is the natural home since everyone already depends on it. Then profile-sync, claims, subscription, geolocation, money-account, sentinel all import from there. Each package keeps its own service URL map.

@mcmire mcmire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, I just have one comment.

init: ({ messenger, options }) =>
new ClaimsService({
messenger,
env: options.env ?? Env.PRD,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe, do we want this to be development by default instead? I don't know what convention we've been using for other services, but it seems like we wouldn't want to hit production unnecessarily.

Alternatively should we make this option required and have clients always pass this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one follow other controllers like profile sync authentication controller, money account api service all default to prd, since for all services with auth we need to follow authentication controller i think we can keep this for now and refactor all controllers to default to dev in the future if needed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 063e097. Configure here.

Comment thread packages/claims-controller/src/ClaimsService.ts Outdated
Comment thread packages/claims-controller/src/ClaimsService.ts Outdated
@tuna1207

tuna1207 commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@mcmire @pedronfigueiredo i have refactored claim service to its own separate data service and resolve all the comments, please help me review again, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants